package io.github.talelin.latticy.mq.consumer;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.rabbitmq.client.Channel;
import io.github.talelin.latticy.bo.StockBO;
import io.github.talelin.latticy.bo.StockOnTheWayBO;
import io.github.talelin.latticy.mapper.StockMapper;
import io.github.talelin.latticy.model.StockDO;
import io.github.talelin.latticy.mq.BaseConsumer;
import io.github.talelin.latticy.mq.MessageHelper;
import io.github.talelin.latticy.service.StockService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.core.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.List;

@Component
@Slf4j
public class StockConsumer implements BaseConsumer {

    @Autowired
    private StockMapper stockMapper;

    public void consume(Message message, Channel channel) throws IOException {
        StockOnTheWayBO stockOnTheWayBO = MessageHelper.msgToObj(message, StockOnTheWayBO.class);
        log.info("收到消息: {}", stockOnTheWayBO.toString());
        List<StockBO> list = stockOnTheWayBO.getList();
        stockMapper.saveOrUpdate(list);

    }

}
